<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link
      rel="stylesheet"
      href="./general-styles-of-descendant-components.css"
    />
  </head>
  <body>
    <div id="root"></div>
    <script src="https://cdn.bootcdn.net/ajax/libs/react/17.0.1/umd/react.development.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/react-dom/17.0.1/umd/react-dom.development.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/prop-types/15.7.2/prop-types.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/Mock.js/1.0.0/mock-min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.0/axios.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/react-router-dom/5.2.0/react-router-dom.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/redux/4.0.5/redux.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/react-redux/7.2.2/react-redux.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/redux-thunk/2.3.0/redux-thunk.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/react-transition-group/4.4.1/react-transition-group.min.js"></script>
    <script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script>
    <script type="text/babel">
      const { Component } = React;

      class Father extends Component {
        state = { carName: "奔驰363" };
        // state = { carName: "奔驰363",a:1,b:2,c:3 };
        changeCar = () => {
          this.setState({
            carName: "迈巴赫",
          });
        };
        shouldComponentUpdate(nextProps, nextState) {
          // console.log(nextProps, nextState);
          // console.log(this.props, this.state);
          if (this.state.carName === nextState.carName) return false;
          else return true;
        }

        changeFakeCar = () => {
          this.setState({});
        };
        render() {
          console.log("Father-render");
          return (
            <div className="Father">
              <h3>我的车名字是:{this.state.carName}</h3>
              <button onClick={this.changeCar}>换车</button>
              <button onClick={this.changeFakeCar}>换假车</button>
              <Son />
              <h6 style={{ color: "white" }}>
                只要改了setState就会render,效率低{`=>`}
                Component原因shouldComponentUpdate
              </h6>
            </div>
          );
        }
      }
      class Son extends Component {
        shouldComponentUpdate(nextProps, nextState) {
          console.log(nextProps, nextState);
          console.log(this.props, this.state);
          // if (this.props.carName === nextProps.carName) {
          //   return false;
          // }
          // return true;
          return !this.props.carName === nextProps.carName;
        }

        render() {
          console.log("Son-render");
          return (
            <div className="Son">
              <h3>我是child组件</h3>
              <h4>我接到的车是:???</h4>
            </div>
          );
        }
      }

      ReactDOM.render(<Father />, document.getElementById("root"));
    </script>
  </body>
</html>
